﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestProject1.MainClasses;
namespace TestProject1
{
    [TestClass]
    public class TestRole
    {
        private IList<Role> RoleList = new List<Role>();
        [TestMethod]
        public void TestMethodRoleInit()
        {   // Проверка инициализации роли

            Role r = new Role();
            Assert.AreEqual(0, r.GetID());
            Assert.AreEqual("", r.Getname());
            Assert.AreEqual(false, r.GetaddTickets());
            Assert.AreEqual(false, r.Getread());
            Assert.AreEqual(false, r.GetsetStatus());
            Assert.AreEqual(false, r.GetStatistics());
            Assert.AreEqual(false, r.GeteditOthersTickets());
            Assert.AreEqual(false, r.GeteditUser());
        }
        [TestMethod]
        public void TestMethodRoleAdd()
        {   // Проверка добавления одной роли в список
            Role r = new Role();
            RoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
            Assert.IsNotNull(RoleList.First().GetID());
            Assert.IsNotNull(RoleList.First().GetaddTickets());
            Assert.IsNotNull(RoleList.First().Getread());
            Assert.IsNotNull(RoleList.First().GetsetStatus());
            Assert.IsNotNull(RoleList.First().GeteditOthersTickets());
            Assert.IsNotNull(RoleList.First().GeteditUser());
            Assert.IsNotNull(RoleList.First());
        }
        [TestMethod]
        public void TestMethodRoleEqualAdding()
        {   // Проверка правильного заполнения полей при добавлении заявки
            Role r = new Role();
            int i = 1111;
            string s1 = "executor";
            bool b1 = true;
            bool b2 = true;
            bool b3 = true;
            bool b4 = true;
            bool b5 = false;
            bool b6 = false;
            RoleList.Add(r.add(101, "administrator", true, true, true, true, true, true));
            Assert.AreNotEqual(i, RoleList.First().GetID());
            Assert.AreNotEqual(s1, RoleList.First().Getname());
            Assert.AreEqual(b1, RoleList.First().GetaddTickets());
            Assert.AreEqual(b2, RoleList.First().GeteditOthersTickets());
            Assert.AreEqual(b3, RoleList.First().GeteditUser());
            Assert.AreEqual(b4, RoleList.First().Getread());
            Assert.AreNotEqual(b5, RoleList.First().GetsetStatus());
            Assert.AreNotEqual(b6, RoleList.First().GetStatistics());
        }

        [TestMethod]
        public void TestMethodRoleAddingToList()
        {   // Проверка добавления нескольких заявок в список     

            Role r1 = new Role();
            RoleList.Add(r1.add(101, "administrator", true, true, true, true, true, true));
            Assert.IsNotNull(RoleList.First());
            Role r2 = new Role();
            RoleList.Add(r2.add(102, "manager", true, false, true, true, false, true));
            Assert.IsNotNull(RoleList.ElementAt(1));
            Role r3 = new Role();
            RoleList.Add(r3.add(103, "executor", true, false, true, true, true, true));
            Assert.IsNotNull(RoleList.ElementAt(2));
            Role r4 = new Role();
            RoleList.Add(r4.add(104, "declarer", true, false, false, true, false, false));
            Assert.IsNotNull(RoleList.ElementAt(3));
            Role r5 = new Role();
            RoleList.Add(r5.add(105, "controller", false, false, false, true, false, true));
            Assert.IsNotNull(RoleList.ElementAt(4));

        }
        [TestMethod]
        public void TestMethodRoleEdit()
        {
            Role r1 = new Role();
            RoleList.Add(r1.add(101, "administrator", true, true, true, true, true, true));
            int i = 1;
            string s1 = "controller";
            bool b1 = false;
            bool b2 = false;
            bool b3 = false;
            bool b4 = true;
            bool b5 = false;
            bool b6 = true;
            RoleList.First().edit(i, s1, b1, b2, b3, b4, b5, b6);
            Assert.AreEqual(i, RoleList.First().GetID());
            Assert.AreEqual(s1, RoleList.First().Getname());
            Assert.AreEqual(b1, RoleList.First().GetaddTickets());
            Assert.AreEqual(b2, RoleList.First().GeteditOthersTickets());
            Assert.AreEqual(b3, RoleList.First().GeteditUser());
            Assert.AreEqual(b4, RoleList.First().Getread());
            Assert.AreEqual(b5, RoleList.First().GetsetStatus());
            Assert.AreEqual(b6, RoleList.First().GetStatistics());
        }

        [TestMethod]
        public void TestMethodRoleRemove()
        {   //Проверка удаления пользователя из списка
            Role r1 = new Role();
            RoleList.Add(r1.add(101, "administrator", true, true, true, true, true, true));
            Role r2 = new Role();
            RoleList.Add(r2.add(102, "manager", true, false, true, true, false, true));
            Role r3 = new Role();
            RoleList.Add(r3.add(103, "executor", true, false, true, true, true, true));
            Role r4 = new Role();
            RoleList.Add(r4.add(104, "declarer", true, false, false, true, false, false));
            Role r5 = new Role();
            RoleList.Add(r5.add(105, "controller", false, false, false, true, false, true));
            int y = RoleList.Count();

            for (int i = 0; i < RoleList.Count(); i++)
            {
                if (RoleList.ElementAt(i).Getname() == "executor")
                {
                    RoleList.RemoveAt(i); y--;
                    Assert.IsNotNull(RoleList.ElementAt(i + 1));
                }
                Assert.AreEqual(y, RoleList.Count());
            }
        }
    }
}